package com.ruoyi.basicsystem.service.impl;

import com.ruoyi.common.utils.SecurityUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ruoyi.common.utils.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.basicsystem.mapper.ZnPersonMapper;
import com.ruoyi.basicsystem.domain.ZnPerson;
import com.ruoyi.basicsystem.service.IZnPersonService;

/**
 * 经手人Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-03-04
 */
@Service
public class ZnPersonServiceImpl implements IZnPersonService 
{
    @Autowired
    private ZnPersonMapper znPersonMapper;

    /**
     * 查询经手人
     * 
     * @param id 经手人主键
     * @return 经手人
     */
    @Override
    public ZnPerson selectZnPersonById(Long id)
    {
        return znPersonMapper.selectZnPersonById(id);
    }

    /**
     * 查询经手人列表
     * 
     * @param znPerson 经手人
     * @return 经手人
     */
    @Override
    public List<ZnPerson> selectZnPersonList(ZnPerson znPerson)
    {
        znPerson.setTenantId(SecurityUtils.getTenantId());
        znPerson.setDeleteFlag("0");
        return znPersonMapper.selectZnPersonList(znPerson);
    }
     /**
      * 查询经手人记录数
      *
      * @param znPerson 经手人
      * @return 经手人记录数
     */
    public Integer selectZnPersonCount(ZnPerson znPerson){
        znPerson.setTenantId(SecurityUtils.getTenantId());
        return znPersonMapper.selectZnPersonCount(znPerson);
    }


    /**
     * 新增经手人
     * 
     * @param znPerson 经手人
     * @return 结果
     */
    @Override
    public int insertZnPerson(ZnPerson znPerson)
    {
       znPerson.setTenantId(SecurityUtils.getTenantId());
        znPerson.setDeleteFlag("0");
        return znPersonMapper.insertZnPerson(znPerson);
    }

    /**
     * 修改经手人
     * 
     * @param znPerson 经手人
     * @return 结果
     */
    @Override
    public int updateZnPerson(ZnPerson znPerson)
    {
        return znPersonMapper.updateZnPerson(znPerson);
    }

    /**
     * 批量删除经手人
     * 
     * @param ids 需要删除的经手人主键
     * @return 结果
     */
    @Override
    public int deleteZnPersonByIds(Long[] ids)
    {
        return znPersonMapper.deleteZnPersonByIds(ids);
    }

    /**
     * 删除经手人信息
     * 
     * @param id 经手人主键
     * @return 结果
     */
    @Override
    public int deleteZnPersonById(Long id)
    {
        return znPersonMapper.deleteZnPersonById(id);
    }

    @Override
    public Map<Long, String> getPersonMap() throws Exception {
        List<ZnPerson> personList = getPerson();
        Map<Long,String> personMap = new HashMap<>();
        for(ZnPerson person : personList){
            personMap.put(person.getId(), person.getName());
        }
        return personMap;
    }

    @Override
    public String getPersonByMapAndIds(Map<Long,String> personMap, String personIds) {
        List<Long> ids = StringUtil.strToLongList(personIds);
        StringBuffer sb = new StringBuffer();
        for(Long id: ids){
            sb.append(personMap.get(id) + " ");
        }
        return sb.toString();
    }
    public List<ZnPerson> getPerson()throws Exception {
        ZnPerson znPerson=new ZnPerson();
        znPerson.setDeleteFlag("0");
        List<ZnPerson> list=znPersonMapper.selectZnPersonList(znPerson);

        return list;
    }
}
